<template>
  <div class="login-container">
    <h1 class="title">会员管理系统</h1>
    <div class="login-box">
      <el-form :model="form" :rules="rules" ref="loginForm" label-width="80px" @submit.prevent>
        <el-form-item label="账号" prop="username" required>
          <template #label>
            <span class="required-star"></span>账号
          </template>
          <el-input v-model="form.username" autocomplete="off" placeholder="请输入账号" />
        </el-form-item>
        <el-form-item label="密码" prop="password" required>
          <template #label>
            <span class="required-star"></span>密码
          </template>
          <el-input v-model="form.password" type="password" autocomplete="off" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item>
          <el-button class="login-btn" type="primary" @click="handleLogin" style="width:100%;font-size:22px;">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { login } from '@/api/auth';

export default {
  name: 'LoginView',
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          login({ username: this.form.username, password: this.form.password }).then(res => {
            if (res.data.code === 200) {
              localStorage.setItem('token', res.data.data.token);
              this.$router.push('/dashboard');
            } else {
              this.$message.error(res.data.msg || '登录失败');
            }
          }).catch(error => {
            this.$message.error('请求失败，请稍后再试');
            console.error(error);
          });
        }
      });
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0e7ff 0%, #f8fafc 100%);
  box-sizing: border-box;
}
.title {
  font-size: 48px;
  font-weight: bold;
  margin-bottom: 40px;
  margin-top: 40px;
  text-align: center;
  color: #2d3a4b;
  text-shadow: 1px 2px 8px #b3c7e6;
}
.login-box {
  border: none;
  box-shadow: 0 8px 32px 0 rgba(60, 90, 180, 0.15), 0 1.5px 6px 0 rgba(60, 90, 180, 0.08);
  padding: 40px 60px 32px 60px;
  background: #fff;
  min-width: 400px;
  border-radius: 18px;
  box-sizing: border-box;
}
.required-star {
  color: #e74c3c;
  margin-right: 2px;
  font-size: 18px;
  font-weight: bold;
}
.login-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(90deg, #7faaff 0%, #9bb7df 100%);
  border: none;
  border-radius: 8px;
  font-size: 24px;
  color: #fff;
  font-weight: bold;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 2px 8px 0 rgba(60, 90, 180, 0.10);
  transition: background 0.2s, box-shadow 0.2s;
}
.login-btn:hover {
  background: linear-gradient(90deg, #5e8bff 0%, #7faaff 100%);
  box-shadow: 0 4px 16px 0 rgba(60, 90, 180, 0.18);
}
</style>